<?php
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', FALSE);
ini_set('display_startup_errors', FALSE);
date_default_timezone_set('Europe/London');
/** Include PHPExcel */
require_once dirname(__FILE__) . '/library/PHPExcel/Classes/PHPExcel/IOFactory.php';

$ean_file_name = 'EAN_code.xlsx';
$sheetDataColors = $sheetDataSizes = $sheetDataBullet = $sheetDataKeyword = array();

if (file_exists('colors_options.xlsx')) {
    $objPHPExcel_colors = PHPExcel_IOFactory::load('colors_options.xlsx');
    $sheetDataColors = $objPHPExcel_colors->getActiveSheet()->toArray(null, true, true, true);
}
if (file_exists('sizes_options.xlsx')) {
    $objPHPExcel_sizes = PHPExcel_IOFactory::load('sizes_options.xlsx');
    $sheetDataSizes = $objPHPExcel_sizes->getActiveSheet()->toArray(null, true, true, true);
}

if (file_exists('bullet_options.xlsx')) {
    $objPHPExcel_bullet = PHPExcel_IOFactory::load('bullet_options.xlsx');
    $sheetDataBullet = $objPHPExcel_bullet->getActiveSheet()->toArray(null, true, true, true);
}

if (file_exists('keyword_options.xlsx')) {
    $objPHPExcel_keyword = PHPExcel_IOFactory::load('keyword_options.xlsx');
    $sheetDataKeyword = $objPHPExcel_keyword->getActiveSheet()->toArray(null, true, true, true);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <meta name="language" content="en"/>
        <title>Input Form</title>
        <meta name="keywords" content="" property="og:site_name"/>
        <meta name="description" content="" property="og:description"/>
        <meta property="og:title" content=""/>
        <meta property="og:image" content=""/>
        <meta content="" property="og:url">
            <link rel="canonical" href=""/>
            <link rel="stylesheet" type="text/css" href="css/reset.css"/>
            <link rel="stylesheet" type="text/css" href="css/style.css"/>
            <link rel="stylesheet" type="text/css" href="css/jquery-ui.min.css"/>
            <link rel="stylesheet" type="text/css" href="css/jquery-ui.theme.min.css"/>
            <link rel="stylesheet" type="text/css" href="css/jquery-ui.structure.min.css"/>
            <script type="text/javascript" src="js/jquery/jquery-2.1.1.min.js"></script>
            <script type="text/javascript" src="js/jquery/jquery.validate.js"></script>
            <script type="text/javascript" src="js/jquery/jquery-ui.min.js"></script>
            <script type="text/javascript" src="js/frontend.js"></script>
    </head>
    <body>
        <div id="container">
            <div id="header" class="header">

            </div>
            <div id="wrapper">
                <div id="content" class="content">
                    <form action="inputFormPost.php" method="post" id="inputFormPost">
                        <div class="one-field pd10">
                            <div class="one-field">
                                <span class="title fll"><i>*</i>Base SKU Name</span>
                                <input class="content fll bikini_onepiece_set" name="BaseSKUName" value=""/>
                                <div class="display-inline-block mgleft10">
                                    <input type="radio" name="IsSetType" value="IsBikiniSet" id="IsBikiniSet" checked/>
                                    <label for="IsBikiniSet">Is Bikini set</label>
                                </div>
                                <div class="display-inline-block mgleft10">
                                    <input type="radio" name="IsSetType" value="IsMixSet" id="IsMixSet"/>
                                    <label for="IsMixSet">Is Mix Set</label>
                                </div>
                                <div class="display-inline-block mgleft10">
                                    <input type="radio" name="IsSetType" value="IsOnePiece" id="IsOnePiece"/>
                                    <label for="IsOnePiece">Is One Piece</label>
                                </div>
                                <div class="display-inline-block mgleft10">
                                    <input type="checkbox" name="EANTestMode" value="1" checked/>
                                    <label for="EANTestMode">EAN Test Mode</label>
                                </div>
                                <div class="display-inline-block mgleft10">
                                    <input type="checkbox" name="StyleBeforeColor" value="1" checked/>
                                    <label for="StyleBeforeColor">Style before Color</label>
                                </div>
                            </div>
                            <div class="clb"></div>
                            <div class="one-field">
                                <span class="title fll">Mix Set TOP SKU</span>
                                <input class="content fll mix_set_only" name="MixSetTOPSKU" value=""/>
                            </div>
                            <div class="clb"></div>
                            <div class="one-field">
                                <span class="title fll">Mix Set BOTTOM SKU</span>
                                <input class="content fll mix_set_only" name="MixSetBOTTOMSKU" value=""/>
                            </div>
                            <div class="clb"></div>
                            <div class="one-field">
                                <span class="title fll">Colors</span>
                                <select class="content fll" name="Colors[]" multiple id="colorList">
                                    <?php foreach ($sheetDataColors as $color) { ?>
                                        <option value="<?php echo $color['A'] . '{|}' . $color['B']; ?>"><?php echo $color['B']; ?></option>
                                    <?php } ?>
                                </select>
                                <a class="mgleft10" href="javascript:void(0);" id="editListColorsBtn">Edit List</a>
                            </div>
                            <div class="clb"></div>
                            <div class="one-field">
                                <span class="title fll"><i>*</i>Sizes</span>
                                <select class="content fll" name="Sizes[]" multiple id="sizeList">
                                    <?php foreach ($sheetDataSizes as $size) { ?>
                                        <option value="<?php echo $size['A'] . '{|}' . $size['B']; ?>"><?php echo $size['B']; ?></option>
                                    <?php } ?>
                                </select>
                                <a class="mgleft10" href="javascript:void(0);" id="editListSizesBtn">Edit List</a>
                                <div class="imgWidth">
                                    <label for="imgWidth">Image Width: </label>
                                    <input class="content" name="imgWidth" value="500"/>
                                </div>
                            </div>
                            <div class="clb"></div>
                            <div class="one-field">
                                <span class="title fll">Description (set)</span>
                                <textarea name="DescriptionSET" class="content fll bikini_mix_set" placeholder="description text here …"></textarea>
                                <div class="generateImageHtml">
                                    <a class="btn viewImagesHTMLSetBtn bikini_mix_set">Get Images HTML</a>
                                </div>
                            </div>
                            <div class="clb"></div>
                            <div class="one-field">
                                <span class="title fll">Description (top)</span>
                                <textarea name="DescriptionTOP" class="content fll bikini_set_only" placeholder="description text here …"></textarea>
                                <div class="generateImageHtml">
                                    <a class="btn viewImagesHTMLTopBtn bikini_set_only">Get Images HTML</a>
                                </div>
                            </div>
                            <div class="clb"></div>
                            <div class="one-field">
                                <span class="title fll">Description (Bottom)</span>
                                <textarea name="DescriptionBOTTOM" class="content fll bikini_set_only" placeholder="description text here …"></textarea>
                                <div class="generateImageHtml">
                                    <a class="btn viewImagesHTMLBottomBtn bikini_set_only">Get Images HTML</a>
                                </div>
                            </div>
                            <div class="clb"></div>
                            <div class="one-field">
                                <span class="title fll">Description (One Piece)</span>
                                <textarea name="DescriptionOnePiece" class="content fll onepiece_set_only" placeholder="description text here …"></textarea>
                                <div class="generateImageHtml">
                                    <a class="btn viewImagesHTMLOnePieceBtn onepiece_set_only">Get Images HTML</a>
                                </div>
                            </div>
                            <div class="clb"></div>
                            <div class="one-field">
                                <span class="title">LINN Category</span>
                                <input class="content" name="LINNCategory" value="Sheridynswim"/>
                            </div>
                            <div class="one-field">
                                <span class="title">Image Base</span>
                                <input class="content" name="ImageBase" value="http://djfsu7re0nxn3.cloudfront.net"/>
                            </div>
                            <div class="two-field">
                                <span class="title">TOP PRICE</span>
                                <input class="content bikini_set_only" name="TOPPRICE" value=""/>
                            </div>
                            <div class="two-field">
                                <span class="title">Top Sale Price</span>
                                <input class="content bikini_set_only" name="TOPSALEPRICE" value=""/>
                            </div>
                            <div class="two-field">
                                <span class="title">BOTTOM PRICE</span>
                                <input class="content bikini_set_only" name="BOTTOMPRICE" value=""/>
                            </div>
                            <div class="two-field">
                                <span class="title">Bottom Sale Price</span>
                                <input class="content bikini_set_only" name="BOTTOMSALEPRICE" value=""/>
                            </div>
                            <div class="two-field">
                                <span class="title">SET PRICE</span>
                                <input class="content bikini_mix_set" name="SETPRICE" value=""/>
                            </div>
                            <div class="two-field">
                                <span class="title">Set Sale Price</span>
                                <input class="content bikini_mix_set" name="SETSALEPRICE" value=""/>
                            </div>
                            <div class="two-field">
                                <span class="title">One Piece Price</span>
                                <input class="content onepiece_set_only" name="OnePiecePrice" value=""/>
                            </div>
                            <div class="two-field">
                                <span class="title">One Piece Sale Price</span>
                                <input class="content onepiece_set_only" name="OnePieceSalePrice" value=""/>
                            </div>
                            <div class="one-field" style="clear: both;">
                                <span class="title">Magento Top Name</span>
                                <input class="content bikini_set_only" name="MagentoTOPName" value=""/>
                            </div>
                            <div class="one-field">
                                <span class="title">Magento Bottom Name</span>
                                <input class="content bikini_set_only" name="MagentoBOTTOMName" value=""/>
                            </div>
                            <div class="one-field">
                                <span class="title">Magento Set Name</span>
                                <input class="content bikini_mix_set" name="MagentoSETName" value=""/>
                            </div>
                            <div class="one-field">
                                <span class="title">Magento One Piece Name</span>
                                <input class="content onepiece_set_only" name="MagentoOnePieceName" value=""/>
                            </div>
                            <div class="one-field">
                                <span class="title">Magento Top Category</span>
                                <input class="content bikini_set_only" name="MagentoTOPCategory" value="9"/>
                            </div>
                            <div class="one-field">
                                <span class="title">Magento Bottom Category</span>
                                <input class="content bikini_set_only" name="MagentoBOTTOMCategory" value="10"/>
                            </div>
                            <div class="one-field">
                                <span class="title">Magento Set Category</span>
                                <input class="content bikini_mix_set" name="MagentoSETCategory" value="3"/>
                            </div>
                            <div class="one-field">
                                <span class="title">Magento One Piece Category</span>
                                <input class="content onepiece_set_only" name="MagentoOnePieceCategory" value="6"/>
                            </div>
                        </div>
                        <div class="one-field bd pd10">
                            <div class="one-field">
                                <span class="title">Prefix for Name</span>
                                <input class="content" name="AMZPrefixForName" value="Sheridyn Swim Women's"/>
                            </div>
                            <div class="one-field">
                                <span class="title">Amazon Item Type Top</span>
                                <input class="content bikini_mix_set" name="AMZItemTypeTOP" value="fashion-bikini-tops"/>
                            </div>                            
                            <div class="one-field">
                                <span class="title">Amazon Item Type Bottom</span>
                                <input class="content bikini_mix_set" name="AMZItemTypeBOTTOM" value="fashion-swimsuit-bottoms-separates"/>
                            </div>
                            <div class="one-field">
                                <span class="title">Amazon Item Type One Piece</span>
                                <input class="content onepiece_set_only" name="AMZItemTypeOnePiece" value="fashion-one-piece-swimsuits"/>
                            </div>

                            <div class="one-field"><span class="title"></span></div>

                            <div class="one-field">
                                <span class="title">Item Width</span>
                                <input class="content" name="AMZItemWidth" value="12"/>
                            </div>
                            <div class="one-field">
                                <span class="title">Item Height</span>
                                <input class="content" name="AMZItemHeight" value="2"/>
                            </div>
                            <div class="one-field">
                                <span class="title">Item Length</span>
                                <input class="content" name="AMZItemLength" value="20"/>
                            </div>
                            <div class="one-field">
                                <span class="title">Item Weight</span>
                                <input class="content" name="AMZItemWeight" value="65"/>
                            </div>
                            <div class="one-field">
                                <span class="title">Amazon Bullet Point 1</span>
                                <select name="AMZBullerPoint1" id="AMZBullerPoint1" class="content">
                                    <option value=""></option>
                                    <?php foreach ($sheetDataBullet as $bullet) { ?>
                                        <option value="<?php echo $bullet['A']; ?>"><?php echo $bullet['A']; ?></option>
                                    <?php } ?>
                                </select>
                                <a class="mgleft10" href="javascript:void(0);" id="editListBulletBtn">Edit List</a>
                            </div>
                            <div class="one-field">
                                <span class="title">Amazon Bullet Point 2</span>
                                <select name="AMZBullerPoint2" id="AMZBullerPoint2" class="content">
                                    <option value=""></option>
                                    <?php foreach ($sheetDataBullet as $bullet) { ?>
                                        <option value="<?php echo $bullet['A']; ?>"><?php echo $bullet['A']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="one-field">
                                <span class="title">Amazon Bullet Point 3</span>
                                <select name="AMZBullerPoint3" id="AMZBullerPoint3" class="content">
                                    <option value=""></option>
                                    <?php foreach ($sheetDataBullet as $bullet) { ?>
                                        <option value="<?php echo $bullet['A']; ?>"><?php echo $bullet['A']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="one-field">
                                <span class="title">Amazon Bullet Point 4</span>
                                <select name="AMZBullerPoint4" id="AMZBullerPoint4" class="content">
                                    <option value=""></option>
                                    <?php foreach ($sheetDataBullet as $bullet) { ?>
                                        <option value="<?php echo $bullet['A']; ?>"><?php echo $bullet['A']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="one-field">
                                <span class="title">Amazon Bullet Point 5</span>
                                <select name="AMZBullerPoint5" id="AMZBullerPoint5" class="content">
                                    <option value=""></option>
                                    <?php foreach ($sheetDataBullet as $bullet) { ?>
                                        <option value="<?php echo $bullet['A']; ?>"><?php echo $bullet['A']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="one-field">
                                <span class="title">Amazon Keyword 1</span>
                                <select name="AMZKeyword1" id="AMZKeyword1" class="content">
                                    <option value=""></option>
                                    <?php foreach ($sheetDataKeyword as $keyword) { ?>
                                        <option value="<?php echo $keyword['A']; ?>"><?php echo $keyword['A']; ?></option>
                                    <?php } ?>
                                </select>
                                <a class="mgleft10" href="javascript:void(0);" id="editListKeywordBtn">Edit List</a>
                            </div>
                            <div class="one-field">
                                <span class="title">Amazon Keyword 2</span>
                                <select name="AMZKeyword2" id="AMZKeyword2" class="content">
                                    <option value=""></option>
                                    <?php foreach ($sheetDataKeyword as $keyword) { ?>
                                        <option value="<?php echo $keyword['A']; ?>"><?php echo $keyword['A']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="one-field">
                                <span class="title">Amazon Keyword 3</span>
                                <select name="AMZKeyword3" id="AMZKeyword3" class="content">
                                    <option value=""></option>
                                    <?php foreach ($sheetDataKeyword as $keyword) { ?>
                                        <option value="<?php echo $keyword['A']; ?>"><?php echo $keyword['A']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="one-field">
                                <span class="title">Amazon Keyword 4</span>
                                <select name="AMZKeyword4" id="AMZKeyword4" class="content">
                                    <option value=""></option>
                                    <?php foreach ($sheetDataKeyword as $keyword) { ?>
                                        <option value="<?php echo $keyword['A']; ?>"><?php echo $keyword['A']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="one-field">
                                <span class="title">Amazon Keyword 5</span>
                                <select name="AMZKeyword5" id="AMZKeyword5" class="content">
                                    <option value=""></option>
                                    <?php foreach ($sheetDataKeyword as $keyword) { ?>
                                        <option value="<?php echo $keyword['A']; ?>"><?php echo $keyword['A']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>

                        <div class="buttons">
                            <input type="hidden" name="actionForm" value="" id="actionForm"/>
                            <button class="mgtop10 btn" data-action="generate-skus">Generate SKUs</button>
                            <button class="mgtop10 btn bikini_mix_set" data-action="generate-composites">Generate COMPOSITES</button>
                            <button class="mgtop10 btn" data-action="generate-magento">GENERATE Magento</button>
                            <button class="mgtop10 btn bikini_onepiece_set" data-action="generate-amazon-usa">GENERATE AMAZON USA</button>
                            <button class="mgtop10 btn bikini_onepiece_set" data-action="generate-amazon-uk">GENERATE AMAZON UK</button>
                            <button class="mgtop10 btn bikini_onepiece_set" data-action="generate-amazon-de">GENERATE AMAZON DE</button>
                            <button class="mgtop10 btn bikini_onepiece_set" data-action="generate-amazon-fr">GENERATE AMAZON FR</button>
                            <a href="downloadean.php" class="mgtop10 btn">Download EAN file</a>
                            <a class="mgtop10 btn" href="javascript:void(0);" id="upLoadBtn">Upload EAN file</a>
                        </div>
                    </form>
                </div>
<!--                <script>
                    function myFunction()
                    {
                    document.getElementById("fm_upLoad").style.display = "";
                    }
                </script>-->
                <div class="kn-popup formShowDialog" id="fm_upLoad" title="Up Load File" style="display: none;">
                    <form action='inputForm.php' method='post' enctype='multipart/form-data'>
                        <div class="content">
<!--                            <div class="one-item header">
                                <span class="value">Value</span>
                            </div>-->
                            <div class="list">

                            </div>
<!--                            <div class="one-item">
                                <a href="javascript:void(0);" class="mgleft10 add-more">Add more</a>
                            </div>-->

                            <div class="list-btn">
                                <button name="upLoadList" id="upLoadList" class="btn">UpLoad</button>
                                <a id="closeUpLoadList" class="btn closeFormDialog">Cancel</a>
                            </div>
                            <div class="clb"></div>
                        </div>
                    </form>
                </div>
            </div>
            <?php
            if (isset($_POST['upLoadList'])) {
                    $tmp = false;                
                if ($_FILES['file']['tmp_name'] != "") {
                    if ($_FILES['file']['type']== "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || $_FILES['file']['type'][$i] == "application/vnd.ms-excel") {
                        $tmpFilePath = $_FILES['file']['tmp_name'];
                        $newFilePath =  $ean_file_name;
                        if (file_exists($newFilePath)) {
                            rename($ean_file_name, rand(1000000, 9999999) . '-' . $ean_file_name."(old)");
                            if (move_uploaded_file($tmpFilePath, $newFilePath)) {
                                    $tmp = true;
                                }
                            } else {
                                if (move_uploaded_file($tmpFilePath, $newFilePath)) {
                                    $tmp = true;
                                }
                         }
                    }
                }
                if ($tmp) {
                    echo '<script language="javascript">';
                    echo 'alert("upload file succesfull")';
                    echo '</script>';
                }else{
                    echo '<script language="javascript">';
                    echo 'alert("Upload failed")';
                    echo '</script>';
                }                
            }
            ?>
            <div id="footer">

            </div>
        </div>
    </body>
</html>

<div class="kn-popup formShowDialog" id="fm_edit_size_list" title="Edit List" style="display: none;">
    <div class="content">
        <div class="one-item header">
            <span class="value">Value</span>
            <span class="name">Name</span>
        </div>
        <div class="list">

        </div>
        <div class="one-item">
            <a href="javascript:void(0);" class="mgleft10 add-more">Add more</a>
        </div>

        <div class="list-btn">
            <button id="updateSizeList">Update</button>
            <button id="closeSizeList" class="closeFormDialog">Cancel</button>
        </div>
        <div class="clb"></div>
    </div>
</div>
<div class="kn-popup formShowDialog" id="fm_edit_color_list" title="Edit List" style="display: none;">
    <div class="content">
        <div class="one-item header">
            <span class="value">Value</span>
            <span class="name">Name</span>
        </div>
        <div class="list">

        </div>
        <div class="one-item">
            <a href="javascript:void(0);" class="mgleft10 add-more">Add more</a>
        </div>

        <div class="list-btn">
            <button id="updateColorList">Update</button>
            <button id="closeColorList" class="closeFormDialog">Cancel</button>
        </div>
        <div class="clb"></div>
    </div>
</div>

<div class="kn-popup formShowDialog" id="fm_edit_keyword_list" title="Edit List" style="display: none;">
    <div class="content">
        <div class="one-item header">
            <span class="value">Value</span>
        </div>
        <div class="list">

        </div>
        <div class="one-item">
            <a href="javascript:void(0);" class="mgleft10 add-more">Add more</a>
        </div>

        <div class="list-btn">
            <button id="updateKeywordList">Update</button>
            <button id="closeKeywordList" class="closeFormDialog">Cancel</button>
        </div>
        <div class="clb"></div>
    </div>
</div>

<div class="kn-popup formShowDialog" id="fm_edit_bullet_point_list" title="Edit List" style="display: none;">
    <div class="content">
        <div class="one-item header">
            <span class="value">Value</span>
        </div>
        <div class="list">

        </div>
        <div class="one-item">
            <a href="javascript:void(0);" class="mgleft10 add-more">Add more</a>
        </div>

        <div class="list-btn">
            <button id="updateBulletList">Update</button>
            <button id="closeBulletList" class="closeFormDialog">Cancel</button>
        </div>
        <div class="clb"></div>
    </div>
</div>

<div class="kn-popup formShowDialog" id="fm_images_html_list" title="Images HTML" style="display: none;">
    <div class="content">
        <textarea class="list" readonly style="width: 99%; height: 200px;"></textarea>
        <div class="list-btn">
            <button id="closeImagesHTMLList" class="closeFormDialog">Close</button>
        </div>
        <div class="clb"></div>
    </div>
</div>